﻿using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;

namespace CAP.Core
{
    internal class Program
    {
        static void Main(string[] args)
        {
            // 1. 创建 ConfigurationBuilder
            var configBuilder = new ConfigurationBuilder()
                .SetBasePath(Path.Combine(Directory.GetCurrentDirectory(), "Configuration")) // 设置配置文件根目录
                .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) // 加载 JSON 配置
                .AddJsonFile("Database.json", optional: false, reloadOnChange: true) // 加载 JSON 配置
                .AddEnvironmentVariables(); // 添加环境变量

            // 2. 构建 IConfiguration 对象
            IConfiguration configuration = configBuilder.Build();

            var host = new WebHostBuilder()
           .UseKestrel()
           .UseConfiguration(configuration) // 将配置注入 WebHost
           .UseContentRoot(Directory.GetCurrentDirectory())
           .UseStartup<Startup>()
           .Build();

            host.Run();
        }
    }
}
